<?php
 /**
 +------------------------------------------------------------------------------
 * Framk PHP框架
 +------------------------------------------------------------------------------
 * @package  Framk
 * @author   shawn fon <ucic5@163.com>
 +------------------------------------------------------------------------------
 */

class Page{
	/////////////////////////////////
	public  $pageLimit,$totalPage,$currentPage=1,$_next;
	private $totalRecords,$pageSize=0,$mainUrl,$pre=1,$begin=1,$_end,$pageFlag,$ext='',$myPath='',$jsDiv;

	public function __construct($p){
		
		$this->pageSize=(int)$GLOBALS['C']['PageSize'];
		$this->_end= $GLOBALS['C']['PageHtmlLen'];
		$this->pageFlag= $GLOBALS['C']['PageFlag'];		
		$this->ext= $GLOBALS['C']['HtmlExt'];
		
		foreach ($p as $key=>$val) {		
		$key = trim($key);
		$this->$key=$val;
		}
		$pageNav=trim(implode('/',$_GET['URL_ARR']),'/');
		$ext=end($_GET['P']);
		if(strpos($ext,$GLOBALS['C']['PageFlag'])===0){
			$this->currentPage=str_replace($GLOBALS['C']['PageFlag'],'',$ext);
			$pageNav=dirname($pageNav);
		}
		$_GET['CPAGE']=$this->currentPage;
		
		$this->mainUrl =ACT.'/'.$pageNav.'/'.$this->pageFlag;
		if(!empty($this->myPath))$this->mainUrl =ACT.$this->myPath.'/'.$this->pageFlag;		 
		$this->totalPage=(int)ceil($this->totalRecords/$this->pageSize); //总页数
		$this->goSize=intval($this->_end/2);              // 页数跳动幅度
				
		$this->pageLimit=($this->currentPage-1)*$this->pageSize.','.$this->pageSize;

		if($this->currentPage>1){
			$this->pre=$this->currentPage-1;  //前一页
		}
		if($this->currentPage==$this->totalPage){
			$this->_next= $this->totalPage; //下一页
		}else{
			$this->_next= $this->currentPage+1; //下一页
		}
		if($this->currentPage>$this->goSize){
			$this->begin=$this->currentPage-$this->goSize;
			$this->_end =$this->currentPage+$this->goSize; //结束页递增到(当前面+gosize)
		}
		
		
	}
/////////////
	public function html($pageType='htmlPage',$jsDiv='#jsPage'){
	
		//if($this->totalRecords<=$this->pageSize)return '';//如果总记录数小于一页要显示的记录数，则不出现页码导航。
		$pageInfo=array('mainUrl'=>$this->mainUrl,'totalPage'=>$this->totalPage,'prePage'=>$this->pre,'nextPage'=>$this->_next,
						'currentPage'=>$this->currentPage,'beginPage'=>$this->begin,'endPage'=>$this->_end,
						'totalRecords'=>$this->totalRecords,'pageSize'=>$this->pageSize,'ext'=>$this->ext,
						'jsDiv'=>$jsDiv,'PageHtmlLen'=>$GLOBALS['C']['PageHtmlLen']);
		$view=new View();
		$view->_assign('pageInfo',$pageInfo);
		$view->_show('tpl_default/'.$pageType);

	}
/////////////////////////////////////
}
?>